<!-- <template>
  <div class="main">
    <div class="btn-group">
      <el-button type="primary" @click="downloadClick">下载</el-button>
      <el-button plain @click="fullscreen">全屏</el-button>
      <el-button plain @click="back">返回</el-button>
    </div>
    <iframe :src="previewUrl" class="iframe" id="iframe" v-if="url"></iframe>
  </div>
</template>

<script>
import { getStatisticsApis } from "@/api/EmengercyPlan/yagl";
import { getStatisticsApi } from "@/api/EmengercyPlan/zsk";
import { Base64 } from "@/lib/base64.js";

export default {
  name: "Preview",
  props: {
    base: {
      type: String,
      default: ""
    },
    url: {
      type: String,
      default: ""
    }
  },
  computed: {
    previewUrl() {
      const url = `${this.base}onlinePreview?url=${encodeURIComponent(Base64.encode(this.url))}`;
      console.log(url);
      return url;
      // return this.url;
    }
  },
  data() {
    return {
      FullScreen: false,
      attachId: ""
    };
  },
  created() {

  },
  mounted() {

  },
  methods: {
    downloadClick() {
      this.$emit("download");
      if (this.$route.name == "KnowledgeBasePreview") {
        // 预览次数统计  0预览 1下载
        // 知识库
        getStatisticsApi({ id: this.$route.query.id, type: 1 }).then(res => {
          console.log(res, "知识库下载");
        });
      } else if (this.$route.name == "PlanManagementPreview") {
        // 预案
        getStatisticsApis({ id: this.$route.query.id, type: 1 }).then(res => {
          console.log(res, "预案下载");
        });
      }
    },

    fullscreen() { // 进入全屏
      const element = document.getElementById("iframe"); // （）填容器需要全屏的id
      if (this.FullScreen) {
        if (document.exitFullscreen) {
          document.exitFullscreen();
        } else if (document.webkitCancelFullScreen) {
          document.webkitCancelFullScreen();
        } else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen();
        } else if (document.msExitFullscreen) {
          document.msExitFullscreen();
        }
      } else {
        if (element.requestFullscreen) {
          element.requestFullscreen();
        } else if (element.webkitRequestFullScreen) {
          element.webkitRequestFullScreen();
        } else if (element.mozRequestFullScreen) {
          element.mozRequestFullScreen();
        } else if (element.msRequestFullscreen) {
          // IE11
          element.msRequestFullscreen();
        }
      }
      // this.FullScreen = !this.FullScreen;
    },
    back() {
      this.$router.back();
    }

  }
};
</script>

<style lang='less' scoped>
.main {
  position: relative;
  height: 100%;
  border-radius: 4px;
  background-color: #fff;
  margin-top: 10px;
  box-sizing: border-box;
  overflow: hidden;

  .btn-group {
    position: absolute;
    top: 2px;
    right: 42px;

    .el-button {
      padding: 6px 20px;
    }
  }

  .iframe {
    height: 100%;
    width: 100%;
    border: 0;
  }
}
</style> -->
